package com.woniu.communitymanagement.controller;

import com.woniu.communitymanagement.entity.HttpResult;
import com.woniu.communitymanagement.entity.User;
import com.woniu.communitymanagement.entity.vo.UserVO;
import com.woniu.communitymanagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户登录
     * @param user 用户名和密码
     * @return 查询返回给页面的信息
     */
    @RequestMapping("/login")
    @CrossOrigin(origins = "*")
    public HttpResult login(@RequestBody UserVO user){
        return userService.selectByNameAndPwd(user.getUsername(), user.getPassword());
    }
    @RequestMapping("/signIn")
    @CrossOrigin(origins = "*")
    public HttpResult signIn(@RequestBody UserVO user){
        return  userService.insertOne(user);
    }
    @RequestMapping("/list")
    @CrossOrigin(origins = "*")
    public HttpResult selectALlUserList(Integer pageIndex,Integer pageSize){
        return userService.selectAllUserList(pageIndex,pageSize);
    }
    @RequestMapping("/update")
    @CrossOrigin(origins = "*")
    public HttpResult updateUserById(@RequestBody User user){
        return userService.updateUserById(user);
    }
    @RequestMapping("/deleteById")
    @CrossOrigin(origins = "*")
    public  HttpResult deleteUserById(Integer id){
        return userService.deleteUserById(id);
    }
    @RequestMapping("/info")
    @CrossOrigin(origins = "*")
    public HttpResult selectUserById(Integer id){
        return userService.selectUserById(id);
    }


}
